package com.ctsi.framework.organise.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.ArrayList;
import java.util.stream.Collectors;

/**
 * @Auther: zhangjw
 * @Date: 2018/7/1 11:15
 * @Description: 扩展spring security User对象
 */
public class SecurityUser extends org.springframework.security.core.userdetails.User {

    private final UserInfo userInfo;

    public SecurityUser(String username,
                        String password,
                        boolean enabled,
                        boolean accountNonExpired,
                        boolean credentialsNonExpired,
                        boolean accountNonLocked,
                        UserInfo userInfo) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, userInfo.getRoles().stream().map(s -> new SimpleGrantedAuthority(s)).collect(Collectors.toList()));
//        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, new ArrayList<>());
        this.userInfo = userInfo;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

}
